﻿using System.Collections.Generic;
using System;
using System.Drawing;

namespace RecruitmentAgency.Models.Utilities
{
    /// <summary>
    /// Provides methods that are useful to a variety of RecruitmentAgency classes
    /// </summary>
    public class CommonMethods
    {
        private const string selectMessage = "Please select an option from the list";

        /// <summary>
        /// Adds the 'please choose' type message to the start of the input list parameter
        /// </summary>
        /// <param name="list">The list to be altered</param>
        /// <returns>A list containing the 'please choose' type message</returns>
        public static List<string> AddSelectMessageToList(List<string> list)
        {
            List<string> combinedList = new List<string> { selectMessage };
            combinedList.AddRange(list);
            return combinedList;
        }

        /// <summary>
        /// Adds the inputMessage parameter to the start of the input list parameter
        /// </summary>
        /// <param name="list">The list to be altered</param>
        /// <param name="inputMessage">The message to add to the start of the input list</param>
        /// <returns>A list containing the input message</returns>
        public static List<string> AddInputMessageToList(List<string> list, string inputMessage)
        {
            List<string> combinedList = new List<string> { inputMessage };
            combinedList.AddRange(list);
            return combinedList;
        }

        /// <summary>
        /// Returns a copy of the input image that has been resized to the input width and height, while keeping the correct proportions
        /// </summary>
        /// <param name="originalImage">The image to resize</param>
        /// <param name="width">The width of the resized image</param>
        /// <param name="maximumHeight">The maximum height of the resized image</param>
        /// <returns>A copy of the input image that has been resized to the input width and height</returns>
        public static Image ResizeImage(Image originalImage, int width, int maximumHeight)
        {
            originalImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
            originalImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
            int height = originalImage.Height * width / originalImage.Width;
            if (height > maximumHeight)
            {
                width = originalImage.Width * maximumHeight / originalImage.Height;
                height = maximumHeight;
            }
            Image sizedImage = originalImage.GetThumbnailImage(width, height, null, IntPtr.Zero);
            return sizedImage;
        }
    }
}